package org.yangjie.controller;

public class ResponseVo<T> {

	private int code;
	private String msg; 
    private T data;

    
    /**
     * 默认成功方法
     * @param data
     * @return
     */
    public static <T> ResponseVo<T> success(T data){
    	return ResponseVo.build(data, CodeEnum.SUCCESS); 
    }

    /**
     * 默认成功方法
     * @param data
     * @return 
     * @return
     */
    public static <T> ResponseVo<T> success(T data, String msg){
    	return ResponseVo.build(data, CodeEnum.SUCCESS.getCode(), msg); 
    }
    
    /**
     * 默认失败方法
     * @param data
     * @return
     */
    public static <T> ResponseVo<T> fail(T data){
    	return ResponseVo.build(data, CodeEnum.FAIL); 
    }
    
    /**
     * 默认失败方法
     * @param data
     * @return
     */
    public static <T> ResponseVo<T> fail(String msg){
    	return ResponseVo.build(null, CodeEnum.FAIL.getCode(), msg); 
    }
    
    /**
     * 默认失败方法
     * @param data
     * @return
     */
    public static <T> ResponseVo<T> fail(T data, String msg){
    	return ResponseVo.build(data, CodeEnum.FAIL.getCode(), msg); 
    }
	
    /**
     * 默认构建方法
     * @param data
     * @return
     */
    public static <T> ResponseVo<T> build(CodeEnum codeEnum){
    	return ResponseVo.build(null, codeEnum); 
    }
    
    /**
     * 默认构建方法
     * @param data
     * @return
     */
    public static <T> ResponseVo<T> build(T data, CodeEnum codeEnum){
    	return ResponseVo.build(data, codeEnum.getCode(), codeEnum.getMsg()); 
    }
    
    /**
     * 默认构建方法
     * @param data
     * @return
     */
    public static <T> ResponseVo<T> build(int code, String msg){
    	return build(null, code, msg); 
    }
    
    /**
     * 默认构建方法
     * @param data
     * @return
     */
    public static <T> ResponseVo<T> build(T data, int code, String msg){
    	ResponseVo<T> responseBean = new ResponseVo<>();
    	responseBean.setCode(code);
    	responseBean.setMsg(msg);
    	responseBean.setData(data);
    	return responseBean; 
    }
    
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getMsg() {
		return msg;
	}
	public void setMsg(String msg) {
		this.msg = msg;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}

}
